<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <el-card>
      <div id="main"></div>
    </el-card>
  </div>
</template>

<script>
import echarts from 'echarts'
import lodash from 'lodash'
export default {
  data() {
    return {
      //配置数据
      options: {
        title: {
          text: '⽤户来源',
          textStyle:{
            fontSize:26,
            fontWidth:600,
          }
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3',
            },
          },
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
          },
        ],
        yAxis: [
          {
            type: 'value',
          },
        ],
      },
    }
  },
  async mounted() {
    //初始化图表--页面渲染完毕
    let mychart = echarts.init(document.getElementById('main'))
    //发起接口请求
    const result = await this.$http({
      url: '/reports/type/1',
    })
    let chart1 = result.data.data
    //合并原始数据和请求数据---lodash的merge方法
    const finallyChart = _.merge(chart1, this.options)
    //将配置项设置给echarts实例对象，使用指定的配置项和数据显示图表
    mychart.setOption(finallyChart)
  },
}
</script>

<style lang="less" scoped>
#main {
  width: 60%;
  height: 400px;
}
</style>
